/**
 * Copyright (C) 2010 altuure <altuure [AT] gmail [DOT] com> http://www.altuure.com/projects/yagdao
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.altuure.yagdao;

import java.io.Serializable;

/**
 * Criteria result set order.
 * @author altuure
 */
public class YOrder implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * Search order
     */
    public enum Sort {
        ASC, DESC
    }

    /**
     * sort field name
     */
    private String name;

    /**
     * sort order
     */
    private Sort sort;

    /**
     * default sort bt desc order;
     * @param name property name and asc
     */
    public YOrder(String name) {
        this(name, Sort.ASC);
    }

    /**
     * Default const
     * @param name sort property
     * @param sort sort order
     */
    public YOrder(String name, Sort sort) {
        super();
        this.name = name;
        this.sort = sort;
    }

    /** sort property
     * @return sort property*/
    public String getName() {
        return name;
    }

    /** sort order
     * @return sorting*/
    public Sort getSort() {
        return sort;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("DAOOrder [name=");
        builder.append(name);
        builder.append(", sort=");
        builder.append(sort);
        builder.append("]");
        return builder.toString();
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + ((sort == null) ? 0 : sort.hashCode());
        return result;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        YOrder other = (YOrder) obj;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        if (sort != other.sort)
            return false;
        return true;
    }

}
